package com.eco.fanliapp.service.impl;

import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.service.ITaoBaoGetDetailDescService;
import com.eco.fanliapp.utils.HttpUtils;
import com.eco.fanliapp.utils.JsonUtils;
import com.eco.fanliapp.vo.TaoBaoGetDetailInfo;
import org.springframework.stereotype.Service;

/**
 * 实现层
 * @author xiaoxx
 * @Time 2019年5月16日下午2:58:21
 *
 */
@Service
public class TaoBaoGetDetailDescServiceImpl implements ITaoBaoGetDetailDescService {

	/**
	 * 获取抓包接口图文详情数据
	 */
	@Override
	public ServerResponse<TaoBaoGetDetailInfo> getTaoBaoGetDetail(String itemId) {
		// TODO Auto-generated method getTaoBaoGetDetail
		//http://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%7B\"itemNumId\"%3A\"579134682267\"%7D;
		StringBuilder builder = new StringBuilder();
		builder.append("http://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/").append("?data=");
		builder.append("%7B%22itemNumId%22%3A%22").append(itemId).append("%22%7D");
		String str = HttpUtils.sendGet(builder.toString(), "");
		if(str != null) {
			TaoBaoGetDetailInfo info = JsonUtils.getJsonToBean(str, TaoBaoGetDetailInfo.class);
			if(info != null && info.getData().getItem() != null && info.getData().getSeller() != null) {
				return ServerResponse.createBySuccess("数据获取成功", info);
			}else {
				return ServerResponse.createBySuccessCodeMessage(201, "暂无数据");
			}
		}else {
			return ServerResponse.createBySuccessCodeMessage(201, "暂无数据");
		}
	}

}
